package com.example.panda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.panda.R;
import com.example.panda.Item.JoinTeamGridItem;

import java.util.List;

public class JoinTeamGridAdapter extends ArrayAdapter {
    Context context;
    List<JoinTeamGridItem> items;
    private  int res;

    public JoinTeamGridAdapter(@NonNull Context context, int resource, List<JoinTeamGridItem> items) {
        super(context, resource);
        this.context=context;
        this.items=items;
        this.res=resource;
    }

    @Override
    public int getCount() {
        return items.size();
    }
    @Override
    public JoinTeamGridItem getItem(int position){
        return items.get(position);
    }
    @Override
    public long getItemId(int position){
        return position;
    }

    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent){
        JoinTeamGridItem item = (JoinTeamGridItem) getItem(position);

        View view = LayoutInflater.from(getContext()).inflate(res,parent,false);

        ImageView imageView =view.findViewById(R.id.grid_img);
        TextView textView = view.findViewById(R.id.grid_tv);
        LinearLayout linearLayout1 =view.findViewById(R.id.grid_ll);
        imageView.setImageResource(item.getImg());
        textView.setText(item.getText());
        linearLayout1.setBackgroundResource(item.getItem_linear());
        return view;

    }
}
